package xin.javashare.designPattern.creation.factoryMethod;

import xin.javashare.designPattern.creation.factoryMethod.service.Sender;
import xin.javashare.designPattern.creation.factoryMethod.service.serviceImp.MailSender;
import xin.javashare.designPattern.creation.factoryMethod.service.serviceImp.SmsSender;

/**
 * 工厂类
 * 工厂方法模式   之   普通工厂模式
 *
 */
public class SendFactory {
    // 普通工厂方法
    public Sender produce(String type) {
        if ("mail".equals(type)) {
            return new MailSender();
        } else if ("sms".equals(type)) {
            return new SmsSender();
        } else {
            System.out.println("请输入正确的类型！");
            return null;
        }
    }

    // 测试
    public static void main(String[] args) {
        SendFactory factory = new SendFactory();
        Sender sender = factory.produce("sms");
        sender.Send();
    }
}

